package com.snailthink.controller;

import com.snailthink.pojo.OrmCustomerVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/customer")
public class CustomerController {

    @GetMapping("/getCustomerName")
    public String getCustomerName(@RequestParam("customerName") String customerName, Model model) {
        //接收参数
        System.out.println(customerName);
        //将参数传递给前端
        model.addAttribute("msg",customerName);
        return "test";
    }

    @GetMapping("/getCustomerName2")
    public String getCustomerName2(@RequestParam("customerName") String customerName, Model model) {
        //接收参数
        System.out.println(customerName);
        //将参数传递给前端
        model.addAttribute("msg",customerName);
        return "test";
    }


    /**
     * 1. 接收前端传递的参数 判断参数的名称是否直接在方法上 可以直接使用
     * 2. 假设传递的是一个对象 匹配对象的字段名，如果名字一致则ok 否则接收不到
     *
     * @param customerVO
     * @param model
     * @return
     */
    @GetMapping("/getCustomerName3")
    public String getCustomerName3(@RequestBody OrmCustomerVO customerVO, Model model){

        //接收参数
        System.out.println(customerVO.toString());
        customerVO.setCustomerName("getCustomerName3");
        //将参数传递给前端
        model.addAttribute("msg",customerVO.getCustomerNo());
        return "test";
    }

    @GetMapping("/getModelMap")
    public String getModelMap(ModelMap modelMap){
        return "test";
    }
}
